import { AllSkillKey, SkillLearnType } from "../../config/SkillConfig";

/** 玩家已经学习到的单个技能属性  作为一个简单对象使用 */
export default class PlayerLearnedSingleSkill{
 
  public skillId:AllSkillKey;
  public skillName:string;
  public skillLvl:number;     //技能等级
  public skillAccuExp:number; //累积经验
  public activate:boolean;   //是否默认激活
  public lvlUpExpParams:number; //继承自config  
  public skllLType:SkillLearnType
  public skillInconPath:string
  public skillDesc:string
  
    /**下一级的基础经验值需求 */
    public static LVL_2_EXP_BASE=100;
 
  constructor(skillId:AllSkillKey,skillName:string,skllLType:SkillLearnType,initSkillExp:number,lvlUpExpParams:number,skillInconPath:string,desc:string,activate:boolean){
    this.skillId=skillId;
    this.skillName=skillName;
    this.skillAccuExp=initSkillExp;      
    this.skillLvl=this.expTrsfSkillLvl(initSkillExp,lvlUpExpParams);    
    this.activate=activate; //由外部判定是否直接激活技能 
    this.lvlUpExpParams=lvlUpExpParams;
    this.skllLType=skllLType;
    this.skillInconPath=skillInconPath;
    this.skillDesc=desc;
  }

  public skillLvlup(exp:number){
    this.skillAccuExp=this.skillAccuExp+exp;
    this.skillLvl=this.expTrsfSkillLvl(this.skillAccuExp,this.lvlUpExpParams);
  }
  
  private expTrsfSkillLvl(exp:number,lvlUpExpParams:number):number{
    let base=PlayerLearnedSingleSkill.LVL_2_EXP_BASE   //第二级技能要的经验 例如系数1.2 下 [100 ,120,144,172...]
    let rs=0
    if(exp<base){
        rs=1
    }else{
        let lstExp=exp
        while(lstExp>0){
            lstExp=lstExp-base
            rs=rs+1
            base=base*lvlUpExpParams
        }
    }
    if(rs>9){
        rs=9
    }
    //console.log("经验exp:",exp,",计算出等级",rs)
    return rs
}

}  